package com.snail.starter.config;

import com.snail.starter.function.FormatProcessor;
import com.snail.starter.function.JsonFormatProcessor;
import com.snail.starter.function.ObjectFormatProcess;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @title: Myconfiguration
 * @Author liwenbo
 * @Date: 2021/8/25 16:05
 */
@Configuration
public class FormatAutoConfiguration {

    @ConditionalOnMissingClass("com.fasterxml.jackson.databind.ObjectMapper")
    @Bean
    @Primary
    public FormatProcessor stringFormat(){
        return new ObjectFormatProcess();
    }

    @ConditionalOnClass(name = "com.fasterxml.jackson.databind.ObjectMapper")
    @Bean
    public FormatProcessor jsonFormat(){
        return new JsonFormatProcessor();
    }
}
